package edu.sctu.boot.admin.generator.utils;

import java.io.StringWriter;
import java.sql.*;
import java.util.*;

public class DbUtils {

    public static Map<String, String> getTableFileds(String table)
            throws SQLException, ClassNotFoundException {

        Connection connection = null;
        Map<String, String> map = new HashMap<String, String>();
        ResultSet rs = null;

        Class.forName("com.mysql.cj.jdbc.Driver");

        connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/boot-admin",
                "root",
                "123456"
        );

//        DatabaseMetaData dbmd = connection.getMetaData();

        rs = connection.getMetaData().getColumns(
                null,
                null,
                table.toUpperCase(Locale.ROOT),
                "%"
        );

        while (rs.next()) {
            String columnName = rs.getString("COLUMN_NAME");
            String remark = rs.getString("REMARKS");

            map.put(columnName, remark);
        }
        rs.close();
        connection.close();

        return map;
    }
}
